{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4498e3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入支付宝余额：10\n",
      "--------校园二手市场（输入“quit”退出）---------\n",
      "商品编号：0，商品名称：吧唧，商品价格：3元\n",
      "商品编号：1，商品名称：立牌，商品价格：4元\n",
      "商品编号：2，商品名称：钥匙扣，商品价格：5元\n",
      "商品编号：3，商品名称：色纸，商品价格：9元\n",
      "商品编号：4，商品名称：收藏卡，商品价格：2元\n",
      "请输入商品编号：4\n",
      "收藏卡已购买成功，您的余额还有：8元\n",
      "--------校园二手市场（输入“quit”退出）---------\n",
      "商品编号：0，商品名称：吧唧，商品价格：3元\n",
      "商品编号：1，商品名称：立牌，商品价格：4元\n",
      "商品编号：2，商品名称：钥匙扣，商品价格：5元\n",
      "商品编号：3，商品名称：色纸，商品价格：9元\n",
      "商品编号：4，商品名称：收藏卡，商品价格：2元\n"
     ]
    }
   ],
   "source": [
    "alipay = int(input(\"请输入支付宝余额：\"))\n",
    "商品列表 = [[\"吧唧\",3],\n",
    "        [\"立牌\",4],\n",
    "        [\"钥匙扣\",5],\n",
    "        [\"色纸\",9],\n",
    "        [\"收藏卡\",2]]\n",
    "\n",
    "购物车 = []\n",
    "\n",
    "while True:\n",
    "    print(\"--------校园二手市场（输入“quit”退出）---------\")\n",
    "    for i in 商品列表:\n",
    "            print(\"商品编号：%s，商品名称：%s，商品价格：%s元\"%(商品列表.index(i),i[0],i[1]))\n",
    "\n",
    "    user_choose = input(\"请输入商品编号：\")\n",
    "    \n",
    "    if user_choose.isdigit():\n",
    "    \n",
    "        if 商品列表[int(user_choose)][1] < int(alipay):\n",
    "            alipay = int(alipay) - 商品列表[int(user_choose)][1]\n",
    "            购物车.append(商品列表[int(user_choose)])\n",
    "            print(\"%s已购买成功，您的余额还有：%s元\"%(商品列表[int(user_choose)][0],alipay))\n",
    "        else:\n",
    "            print(\"就%s元，还想买%s，逛一逛别的商品吧\"%(alipay,商品列表[int(user_choose)][0]))\n",
    "    \n",
    "    elif user_choose == \"quit\":\n",
    "        print(\"您的购物车：%s，您的余额还剩：%s元\"%(购物车,alipay))\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入正确的商品编号或者输入“quit”退出\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bc18d518",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['钥匙扣', 5]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "商品列表[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9e5c7206",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "商品列表[2][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "840129d6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
